import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:laos_mall/common/base/page_size_controller.dart';
import 'package:laos_mall/common/utils/http_util.dart';
import 'package:laos_mall/common/utils/widget_util.dart';
import 'package:laos_mall/models/order/order_model.dart';

class OrderLogic extends PageSizeLogic with GetTickerProviderStateMixin {
  late TabController tabController;
  final tabBarNames = ["all", "in_store", "online", "returns"];

  @override
  void initConfig() {
    tabController = TabController(length: tabBarNames.length, vsync: this);
    var arg = Get.arguments;
    tabController.index = arg ?? 0;
    super.initConfig();
  }

  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }
}

class OrderItemLogic extends PageSizeLogic<OrderItemModel> {
  OrderItemLogic(this.tag);

  final String tag;

  @override
  bool get autoPage => false;

  @override
  Future<List<OrderItemModel>?> Function()? get future => () async {
        int orderState = -1;
        int pay_type_id = -1;
        switch(tag){
          case "returns":
            orderState = 3;
          case "in_store":
            pay_type_id = 1;
          case "online":
            pay_type_id = 0;
        }

        var param = {
          "page": 1,
          "sort_field": "add_time",
          "sort_order": "desc",
          "keyword": "",
          "pay_status": -1,
          "order_status": orderState,
          "date_type": 1,
          "is_offline":pay_type_id
        };
        var res = await HttpUtil.restApi.orderList(param);
        return res.data?.filter_result;
      };

  cancelOrder(int? id)async{
    WidgetUtil.showBottomSheet("hint_cancel_order".tr, "", ()async {
      var res = await HttpUtil.restApi.cancelOrder({"id":id});
      onRefresh();
    });


  }
}
